package cn.jjxx.modules.iface.controller;


import cn.jjxx.core.model.AjaxJson;
import cn.jjxx.core.query.wrapper.EntityWrapper;
import cn.jjxx.modules.te.entity.TeEquipmentTrend;
import cn.jjxx.modules.te.entity.TeMaterialComparison;
import cn.jjxx.modules.te.entity.TeMaterialMonth;
import cn.jjxx.modules.te.entity.TeWeekMaterial;
import cn.jjxx.modules.te.service.ITeEquipmentTrendService;
import cn.jjxx.modules.te.service.ITeMaterialComparisonService;
import cn.jjxx.modules.te.service.ITeMaterialMonthService;
import cn.jjxx.modules.te.service.ITeWeekMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/iface/road-bridge-tech-equipment")
public class RoadBridgeTechEquipmentController {
    @Autowired
    private ITeWeekMaterialService weekMaterialService;
    @Autowired
    private ITeEquipmentTrendService equipmentTrendService;
    @Autowired
    private ITeMaterialMonthService materialMonthService;
    @Autowired
    private ITeMaterialComparisonService materialComparisonService;

    @RequestMapping(value = "week-material")
    public AjaxJson getWeekMaterial(){
        AjaxJson json = new AjaxJson();
        EntityWrapper<TeWeekMaterial> wrapper = new EntityWrapper<>();
        wrapper.orderBy("name");
        List<TeWeekMaterial> results = weekMaterialService.selectList(wrapper);
        List<Map<String,String>> resultMap = new ArrayList<>();
        for(TeWeekMaterial bean:results){
            BeanMap map = BeanMap.create(bean);
            Map<String,String> map2 = new HashMap<>();
            map2.putAll(map);
            String fullName =String.format("%s(%s)",bean.getName(),bean.getUnit());
            map2.put("fullName",fullName);
            resultMap.add(map2);
        }
        json.setData(resultMap);
        json.success("success");
        return json;
    }

    @RequestMapping(value = "equipment-trend")
    public AjaxJson getEquipmentTrend(){
        AjaxJson json = new AjaxJson();
        EntityWrapper<TeEquipmentTrend> wrapper = new EntityWrapper<>();
        wrapper.orderBy("name");
        List<TeEquipmentTrend> result = equipmentTrendService.selectList(wrapper);
        json.setData(result);
        json.success("success");
        return json;
    }

    @RequestMapping(value = "material-month")
    public AjaxJson getMaterialMonth(){
        AjaxJson json = new AjaxJson();
        EntityWrapper<TeMaterialMonth> wrapper = new EntityWrapper<>();
        wrapper.orderBy("org");
        List<TeMaterialMonth> result = materialMonthService.selectList(wrapper);
        json.setData(result);
        json.success("success");
        return json;
    }

    @RequestMapping(value = "material-comparison")
    public AjaxJson getMaterialComparison(){
        AjaxJson json = new AjaxJson();
        EntityWrapper<TeMaterialComparison> wrapper = new EntityWrapper<>();
        wrapper.orderBy("org");
        List<TeMaterialComparison> result = materialComparisonService.selectList(wrapper);
        json.setData(result);
        json.success("success");
        return json;
    }

}
